package single

import (
	"gitee.com/ichub/goconfig/common/base/basedto"
	"gitee.com/ichub/goconfig/common/base/baseiface"
	"gitee.com/ichub/goconfig/common/basedi"
	"gitee.com/ichub/godi/di/didto"
	"gitee.com/ichub/godi/di/difactroy"
	"github.com/sirupsen/logrus"
	"github.com/stretchr/testify/assert"
	"testing"
)

var DiFactroy = difactroy.FindBeanDiFactroy()

// find single is same
func Test001_SingleAutoRegister(t *testing.T) {

	var bean1 = FindBeanSingleEntity()

	bean1.Name = "111"
	var bean2 = FindBeanSingleEntity()
	var bean3 = FindBeanSingleEntity()
	bean2.Name = "1111222"
	logrus.Info(bean1, bean2, bean3)
	assert.Equal(t, bean2.Name == bean1.Name, true)
	assert.Equal(t, bean3.Name == bean1.Name, true)

}

func Test002_create(t *testing.T) {
	var single = NewSingleEntity()
	logrus.Info(single.ToPrettyString())
	single.Check()
	var s1 baseiface.ISingleton = single
	s1.(*SingleEntity).Id = 111
	logrus.Info("is=:", s1, s1.Single())
	logrus.Info("s=", single, single.Single())

}

func Test002_RegisterFindProxy(t *testing.T) {
	basedi.RegisterBean("ichubresult", basedto.NewIchubResult())
	var beanProxy = basedi.FindBeanProxy("ichubresult")
	logrus.Info("proxy=", beanProxy.(baseiface.ISingleton).Single())

}

// find single is same
func Test003_FindSingle(t *testing.T) {
	//	basedi.RegisterLoadBean("single", LoadSingleEntity)
	var bean1 = basedi.FindBean("single")
	bean1.(*SingleEntity).Name = "111"
	logrus.Info("proxy1=", bean1, bean1.Single())

	var bean2 = basedi.FindBean("single")
	var bean3 = basedi.FindBean("single")
	bean2.(*SingleEntity).Name = "1111222"
	logrus.Info("proxy1=", bean1, bean1.Single())
	logrus.Info("proxy2=", bean2, bean2.Single(), bean3)

}

type demo struct {
}

func (d demo) Single() bool {
	//TODO implement me
	panic("implement me")
}

func (d demo) Autoload() bool {
	//TODO implement me
	panic("implement me")
}

func (d demo) AutoInject() bool {
	//TODO implement me
	panic("implement me")
}

func (d demo) InitProxy(some any) {
	//TODO implement me
	panic("implement me")
}

type demo1 struct {
	baseiface.ISingleton
}

func (this *demo1) AutoInject() bool {
	return true
}
func Test006(t *testing.T) {
	var demo = &demo1{}
	logrus.Info(demo.AutoInject())
	var x any
	x = 200
	value, ok := x.(int)
	logrus.Info(value, ok)
}
func Test007_makedi(t *testing.T) {

	var dto = didto.FindBeanDiDto() //NewDiDto()
	dto.PkgName = "single"
	dto.StructName = "SingleEntity"
	DiFactroy.MakeDi(dto)
}
